package spikes_goods_sku

import (
	
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/model/spikes_goods_sku"
    spikes_goods_skuReq "github.com/flipped-aurora/gin-vue-admin/server/model/spikes_goods_sku/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type SpikesGoodsSkusApi struct {}



// CreateSpikesGoodsSkus 创建spikesGoodsSkus表
// @Tags SpikesGoodsSkus
// @Summary 创建spikesGoodsSkus表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body spikes_goods_sku.SpikesGoodsSkus true "创建spikesGoodsSkus表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /spikesGoodsSkus/createSpikesGoodsSkus [post]
func (spikesGoodsSkusApi *SpikesGoodsSkusApi) CreateSpikesGoodsSkus(c *gin.Context) {
	var spikesGoodsSkus spikes_goods_sku.SpikesGoodsSkus
	err := c.ShouldBindJSON(&spikesGoodsSkus)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = spikesGoodsSkusService.CreateSpikesGoodsSkus(&spikesGoodsSkus)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteSpikesGoodsSkus 删除spikesGoodsSkus表
// @Tags SpikesGoodsSkus
// @Summary 删除spikesGoodsSkus表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body spikes_goods_sku.SpikesGoodsSkus true "删除spikesGoodsSkus表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /spikesGoodsSkus/deleteSpikesGoodsSkus [delete]
func (spikesGoodsSkusApi *SpikesGoodsSkusApi) DeleteSpikesGoodsSkus(c *gin.Context) {
	ID := c.Query("ID")
	err := spikesGoodsSkusService.DeleteSpikesGoodsSkus(ID)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteSpikesGoodsSkusByIds 批量删除spikesGoodsSkus表
// @Tags SpikesGoodsSkus
// @Summary 批量删除spikesGoodsSkus表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /spikesGoodsSkus/deleteSpikesGoodsSkusByIds [delete]
func (spikesGoodsSkusApi *SpikesGoodsSkusApi) DeleteSpikesGoodsSkusByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
	err := spikesGoodsSkusService.DeleteSpikesGoodsSkusByIds(IDs)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateSpikesGoodsSkus 更新spikesGoodsSkus表
// @Tags SpikesGoodsSkus
// @Summary 更新spikesGoodsSkus表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body spikes_goods_sku.SpikesGoodsSkus true "更新spikesGoodsSkus表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /spikesGoodsSkus/updateSpikesGoodsSkus [put]
func (spikesGoodsSkusApi *SpikesGoodsSkusApi) UpdateSpikesGoodsSkus(c *gin.Context) {
	var spikesGoodsSkus spikes_goods_sku.SpikesGoodsSkus
	err := c.ShouldBindJSON(&spikesGoodsSkus)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = spikesGoodsSkusService.UpdateSpikesGoodsSkus(spikesGoodsSkus)
	if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindSpikesGoodsSkus 用id查询spikesGoodsSkus表
// @Tags SpikesGoodsSkus
// @Summary 用id查询spikesGoodsSkus表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query spikes_goods_sku.SpikesGoodsSkus true "用id查询spikesGoodsSkus表"
// @Success 200 {object} response.Response{data=spikes_goods_sku.SpikesGoodsSkus,msg=string} "查询成功"
// @Router /spikesGoodsSkus/findSpikesGoodsSkus [get]
func (spikesGoodsSkusApi *SpikesGoodsSkusApi) FindSpikesGoodsSkus(c *gin.Context) {
	ID := c.Query("ID")
	respikesGoodsSkus, err := spikesGoodsSkusService.GetSpikesGoodsSkus(ID)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
	response.OkWithData(respikesGoodsSkus, c)
}
// GetSpikesGoodsSkusList 分页获取spikesGoodsSkus表列表
// @Tags SpikesGoodsSkus
// @Summary 分页获取spikesGoodsSkus表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query spikes_goods_skuReq.SpikesGoodsSkusSearch true "分页获取spikesGoodsSkus表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /spikesGoodsSkus/getSpikesGoodsSkusList [get]
func (spikesGoodsSkusApi *SpikesGoodsSkusApi) GetSpikesGoodsSkusList(c *gin.Context) {
	var pageInfo spikes_goods_skuReq.SpikesGoodsSkusSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := spikesGoodsSkusService.GetSpikesGoodsSkusInfoList(pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}

// GetSpikesGoodsSkusPublic 不需要鉴权的spikesGoodsSkus表接口
// @Tags SpikesGoodsSkus
// @Summary 不需要鉴权的spikesGoodsSkus表接口
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /spikesGoodsSkus/getSpikesGoodsSkusPublic [get]
func (spikesGoodsSkusApi *SpikesGoodsSkusApi) GetSpikesGoodsSkusPublic(c *gin.Context) {
    // 此接口不需要鉴权
    // 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    spikesGoodsSkusService.GetSpikesGoodsSkusPublic()
    response.OkWithDetailed(gin.H{
       "info": "不需要鉴权的spikesGoodsSkus表接口信息",
    }, "获取成功", c)
}
